package cn.com.shopec.erp.base.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.hibernate.type.StandardBasicTypes;
import org.springframework.stereotype.Repository;

import cn.com.shopec.erp.base.dao.ISupplierAccountsDao;
import cn.com.shopec.erp.base.entity.SupplierAccounts;
import cn.com.shopec.erp.base.vo.SupplierAccountsVo;
import cn.com.shopec.erp.common.orm.impl.HibernateEntityDao;

@Repository
public class SupplierAccountsDaoImpl extends HibernateEntityDao<SupplierAccounts> implements ISupplierAccountsDao{

	/***
	 * 根据品牌编号查询供应商信息
	 */
	@Override
	public List<SupplierAccountsVo> getSupplierAccountsListByNo(String no) {
		List<SupplierAccountsVo> suplist = null;
		if(!no.equals("") && no!=null){

			StringBuffer sql = new StringBuffer();
			sql.append(" select t.id as id,"
					+ "t.ACCOUNTS_TYPE as accountsType,"
					+ "t.POINTS_SCALE as pointsScale,"
					+ "t.ACCOUNTS_WAY as accountsWay,"
					+ "t.ACCOUNTS_TIME as accountsTime,"
					+ "t.DELETE_FLAG as deleteFlag,"
					+ "t.CODE as code,"
					+ "t.BRAND_NAME as brandName,"
					+ "t.BRAND_CODE as brandCode,"
					+ "b.SUP_NAME as supName "
					+ "FROM TBL_SUPPLIER_ACCOUNTS t "
					+ "INNER JOIN TBL_SUPPLIER_INFO b on t.CODE = b.CODE "
					+ "WHERE t.BRAND_CODE = '"+no+"' AND t.DELETE_FLAG = 1");
			Query query= getSession().createSQLQuery(sql.toString())
					.addScalar("id",StandardBasicTypes.STRING)
					.addScalar("accountsType",StandardBasicTypes.STRING)
					.addScalar("pointsScale",StandardBasicTypes.STRING)
					.addScalar("accountsWay",StandardBasicTypes.STRING)
					.addScalar("accountsTime",StandardBasicTypes.STRING)
					.addScalar("deleteFlag",StandardBasicTypes.INTEGER)
					.addScalar("code",StandardBasicTypes.STRING)
					.addScalar("brandName",StandardBasicTypes.STRING)
					.addScalar("brandCode",StandardBasicTypes.STRING)
					.addScalar("supName",StandardBasicTypes.STRING);
			query.setResultTransformer(Transformers.aliasToBean(SupplierAccountsVo.class));
			suplist = (List<SupplierAccountsVo>)query.list();
			return suplist;
		}
		return suplist;
	}

}
